package com.lianzhihui.minitiktok.model;

import android.content.Context;

import com.echofeng.common.net.APIConstant;
import com.echofeng.common.net.HttpManager;
import com.echofeng.common.net.HttpManagerCallback;
import com.echofeng.common.net.ResultData;
import com.echofeng.common.utils.GsonUtil;
import com.lianzhihui.minitiktok.bean.hot.VideoResponse;
import com.lianzhihui.minitiktok.bean.user.UserInfo;
import com.net.core.exception.ApiException;
import com.net.core.model.HttpParams;

import java.util.List;

//网络数据请求实现
public class UserHomeModelImp {
    private Context context;
    UserHomeModelInterface userHomeModelInterface;
    public UserHomeModelImp(Context context, UserHomeModelInterface userHomeModelInterface){
        this.context = context;
        this.userHomeModelInterface = userHomeModelInterface;
    }

    public void getMineInfo() {
        HttpParams params = new HttpParams();
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                UserInfo data = GsonUtil.GsonToBean(o.getDataDecryption(), UserInfo.class);
                userHomeModelInterface.onMineInfoSuccess(data);
            }

            @Override
            public void onError(ApiException e) {
                userHomeModelInterface.onFailure(e);
            }
        }).post(APIConstant.GET_MINE_INFO,params);
    }

    public void getUserInfo(String code) {
        HttpParams params = new HttpParams();
        params.put("code",code);
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                UserInfo data = GsonUtil.GsonToBean(o.getDataDecryption(), UserInfo.class);
                userHomeModelInterface.onUserInfoSuccess(data);
            }

            @Override
            public void onError(ApiException e) {
                userHomeModelInterface.onFailure(e);
            }
        }).post(APIConstant.GET_USER_INFO,params);
    }
}
